(function($){

    /*
function b05poll(){
    $.ajax({ url: "/api/cusb05", success: function(data){
        //Update your dashboard gauge
        //salesGauge.setValue(data.value);
                if (!data) return;
                console.log(data.value);

    }, dataType: "json", complete: b05poll, timeout: 30000 });

    */
    $.heyflow.Modules.CUSB05={
        taskid:null,
        init:function(){
            $.heyflow.Toolbar.hide();
            $('#detailpad').hide();
            $.heyflow.loadForm('cusb05',function(data){
                    $('#datapad').html(data);
                    $("#datapad #date1").datepicker({ dateFormat: 'yy-mm-dd', showButtonPanel: true });
                    $("#datapad #date2").datepicker({ dateFormat: 'yy-mm-dd', showButtonPanel: true });

                    $.heyflow.ActiveModule=$.heyflow.Modules.CUSB05
                    $("#datapad #ok").click($.heyflow.ActiveModule.caculate);
                });
                    
            ;},
        caculate:function(){
            var d1=$("#datapad #date1").datepicker('getDate');
            var d2=$("#datapad #date2").datepicker('getDate');
            d1=$.datepicker.formatDate('yymmdd',d1);
            d2=$.datepicker.formatDate('yymmdd',d2);
            console.log(d1+'-'+d2);//'caculate.'+$.datepicker.formatDate('yymmdd',d1));//+'-'+d2.formatDate('yymmdd'));
            $.get('/api/cusb05',{'d1':d1,'d2':d2,t:$.heyflow.Token.encrKey()},function(d){
                    if (d.STATUS==200){
                        $.heyflow.Modules.CUSB05.taskid=d.DATA[0];
                        $.heyflow.Modules.CUSB05.timeit=d.DATA[1];
                        $('#cusb05 #prog').progressbar({value:0});
                        console.log(d.DATA);
                        $.heyflow.Modules.CUSB05.oncaculate();
                        ;}
                    ;},'json');
            ;},
        oncaculate:function(){
            $.get('/api/cusb05',{t:$.heyflow.Token.encrKey(),tsk:$.heyflow.Modules.CUSB05.taskid},function(d){
                    if(d.STATUS==200){
                        d=d.DATA;
                        if(d.FIN){
                            $('#cusb05 #prog').progressbar('value',100);}
                            //$('#cusb05 #prog').progressbar('destroy');}
                        else{
                            $('#cusb05 #prog').progressbar('value',d.val);
                            setTimeout('$.heyflow.Modules.CUSB05.oncaculate();',$.heyflow.Modules.CUSB05.timeit);}}}
                ,'json')},
    }
})(jQuery);
